import { isString } from "./isString";
import { isNumber } from "./isNumber";
export function setCookie(name, value) {
	var path = "/";
	var seconds;
	var domain;
	var expires;
	if(arguments.length > 2) {
		for(var i = 2; i < arguments.length; i++) {
			if(isNumber(arguments[i])) {
				seconds = arguments[i];
			} else if(isString(arguments[i])) {
				if(arguments[i].indexOf("/") >= 0) {
					path = arguments[i];
				} else if(arguments[i].indexOf(".") >= 0) {
					domain = arguments[i];
				}
			}
		}
	}
	if(value == null || seconds <= 0) {
		value = '';
		seconds = -2592000;
	}
	if(!isNaN(seconds)) {
		expires = new Date();
		expires.setTime(expires.getTime() + seconds * 1000);
	}
	document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ '; path=' + path
		+ (domain ? '; domain=' + domain : '')
		+ (location.protocol === 'https:' ? '; secure' : '');
};